package com.moss.cloud.base.biz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.moss.cloud.base.api.model.from.BaseFrom;
import com.moss.cloud.base.api.model.from.SysRoleFrom;
import com.moss.cloud.base.api.model.param.RolePageParam;
import com.moss.cloud.base.biz.service.ISysRoleService;
import com.moss.cloud.common.base.model.po.SysRole;
import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(ServiceList.BASE + "/sysRole")
public class SysRoleController {
    private ISysRoleService sysRoleService;

    public SysRoleController(ISysRoleService sysRoleService) {
        this.sysRoleService = sysRoleService;
    }

    /**
     * 角色ID查询角色信息
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/roleInfo")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "角色ID查询角色信息")
    public Result<?> roleInfo(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(sysRoleService.roleInfo(baseFrom.getId()));
    }

    /**
     * 获取租户角色列表
     *
     * @return
     */
    @PostMapping("/roleList")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "角色ID查询角色信息")
    public Result<?> sysRoles() {
        return Result.success(sysRoleService.sysRoles());
    }

    /**
     * 分页查询租户角色信息
     *
     * @param rolePageParam
     * @return
     */
    @PostMapping("/rolePage")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "分页查询租户角色信息")
    public Result<?> rolePage(@RequestBody RolePageParam rolePageParam) {
        return Result.success(sysRoleService.rolePage(rolePageParam));
    }

    /**
     * 删除角色信息
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/removeRole")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "删除角色信息")
    public Result<?> removeRole(@RequestBody @Validated BaseFrom baseFrom) {
        return Result.success(sysRoleService.removeRole(baseFrom));
    }

    /**
     * 新增角色信息
     *
     * @param sysRoleFrom
     * @return
     */
    @PostMapping("/addRole")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "新增角色信息")
    public Result<?> addRole(@RequestBody @Validated SysRoleFrom sysRoleFrom) {
        return Result.success(sysRoleService.addRole(sysRoleFrom));
    }

    /**
     * 编辑角色信息
     *
     * @param sysRoleFrom
     * @return
     */
    @PostMapping("/updateRole")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_BASE, operation = "编辑角色信息")
    public Result<?> updateRole(@RequestBody @Validated SysRoleFrom sysRoleFrom) {
        return Result.success(sysRoleService.updateRole(sysRoleFrom));
    }

}
